package com.hyx.api.service.impl.pc_admin;

import java.util.List;
import java.util.Arrays;
import com.baomidou.mybatisplus.core.toolkit.ObjectUtils;
import com.hyx.api.domain.CompanyRecoverInfo;
import com.hyx.api.domain.bo.CompanyRecoverInfoBo;
import com.hyx.api.domain.vo.CompanyRecoverInfoVo;
import com.hyx.api.mapper.CompanyRecoverInfoMapper;
import com.hyx.api.service.pc_admin.ICompanyRecoverInfoService;
import org.springframework.beans.BeanUtils;
import org.springframework.stereotype.Service;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import lombok.RequiredArgsConstructor;

/**
 * 公司回收商合作关联Service业务层处理
 *
 * @author ruoyi
 * @date 2023-10-25
 */
@RequiredArgsConstructor
@Service
public class CompanyRecoverInfoServiceImpl implements ICompanyRecoverInfoService
{
    private final CompanyRecoverInfoMapper companyRecoverInfoMapper;

    /**
     * 查询公司回收商合作关联
     *
     * @param id 公司回收商合作关联主键
     * @return 公司回收商合作关联
     */
    @Override
    public CompanyRecoverInfoVo selectCompanyRecoverInfoById(Long id)
    {
        //TODO 表以外的字段，写入vo
        return companyRecoverInfoMapper.selectVoById(id);
    }

    /**
     * 查询公司回收商合作关联列表
     *
     * @param bo 公司回收商合作关联
     * @return 公司回收商合作关联
     */
    @Override
    public List<CompanyRecoverInfoVo> selectCompanyRecoverInfoList(CompanyRecoverInfoBo bo)
    {
        LambdaQueryWrapper<CompanyRecoverInfo> lqw = Wrappers.lambdaQuery();
        lqw.eq(ObjectUtils.isNotEmpty(bo.getRecoveryId()), CompanyRecoverInfo::getRecoveryId, bo.getRecoveryId());
        lqw.eq(ObjectUtils.isNotEmpty(bo.getCompanyId()), CompanyRecoverInfo::getCompanyId, bo.getCompanyId());
        return companyRecoverInfoMapper.selectVoList(lqw);
    }

    /**
     * 新增公司回收商合作关联
     *
     * @param bo 公司回收商合作关联
     * @return 结果
     */
    @Override
    public int insertCompanyRecoverInfo(CompanyRecoverInfoBo bo)
    {
        CompanyRecoverInfo companyRecoverInfo = tranEntityBeforeSave(bo);
        validEntityBeforeSave(companyRecoverInfo);
        return companyRecoverInfoMapper.insert(companyRecoverInfo);
    }

    /**
     * 修改公司回收商合作关联
     *
     * @param bo 公司回收商合作关联
     * @return 结果
     */
    @Override
    public int updateCompanyRecoverInfo(CompanyRecoverInfoBo bo)
    {
        CompanyRecoverInfo companyRecoverInfo = tranEntityBeforeSave(bo);
        return companyRecoverInfoMapper.updateById(companyRecoverInfo);
    }

    /**
     * 批量删除公司回收商合作关联
     *
     * @param ids 需要删除的公司回收商合作关联主键
     * @return 结果
     */
    @Override
    public int deleteCompanyRecoverInfoByIds(Long[] ids)
    {
        return companyRecoverInfoMapper.deleteBatchIds(Arrays.asList(ids));
    }

    /**
     * 保存前的数据校验
     */
    private void validEntityBeforeSave(CompanyRecoverInfo entity) {
        //TODO 做一些数据校验,如唯一约束
    }

    /**
     *   保存前的数据转换
     */
    private CompanyRecoverInfo tranEntityBeforeSave(CompanyRecoverInfoBo bo) {
        //TODO 做一些数据转换
        CompanyRecoverInfo companyRecoverInfo = new CompanyRecoverInfo();
        BeanUtils.copyProperties(bo, companyRecoverInfo);
        return companyRecoverInfo;
    }
}

